package Dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import utils.DBUtils;
import bean.RegisterResult;

public class RegisterDao {
	private DBUtils dbUtils;
	public RegisterDao(){
		dbUtils=DBUtils.getInstance();
	}
	public RegisterResult startRegister(List<Object> params){
		RegisterResult registerResult=new RegisterResult();
		String sql="select * from user_tb where user_name= ? ";
		String sqlInsert="insert into user_tb (user_name,user_pwd,user_type) values ( ? , ? , ?) ";
		List<Object> paramsQuery = new ArrayList<Object>();
		paramsQuery.add(params.get(0));
		dbUtils.getConnection();
		Map<String,Object> map=null;
		try {
			map=dbUtils.queryOneMap(sql, paramsQuery);
			if(!map.isEmpty()){
				//user has already in the database
				registerResult.setResultCode(-1);
			}
			else
			{
				boolean flag=dbUtils.updateOrDelSQL(sqlInsert, params);
				if(flag){
				registerResult.setResultCode(1);
				}
			}
		} catch (Exception e) {
		e.printStackTrace();
		}
		return registerResult;
	}

}
